package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.UserLog;
import com.vne.skyemart.service.UserLogService;

@Controller
@SessionAttributes
@RequestMapping("/userLog")
public class UserLogController {

	@Autowired
	private UserLogService userLogService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveUserLog(@ModelAttribute(" userLog") UserLog userLog,
			BindingResult result) {
		userLogService.addUserLog(userLog);
		return new ModelAndView("redirect:/userLog.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listUserLog(Model model) {
		model.addAttribute("userLog",  userLogService.listUserLog());

		return "userLogList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addUserLog(@ModelAttribute("userLog") UserLog userLog,
			BindingResult result) {
		return new ModelAndView("addUserLog");
	}

}